package com.nowcoder.code.hjnc;

import com.algorithm.model.TreeNode;

import java.util.ArrayList;
import java.util.List;

public class NC45 {

    public static void main(String[] args) {

    }

    /**
     * @param root TreeNode类 the root of binary tree
     * @return int整型二维数组
     */
    public int[][] threeOrders(TreeNode root) {

        int[][] result = new int[3][];

        prevOrder(root);
        result[0] = new int[list.size()];
        for (int i = 0; i < list.size(); i++) {
            result[0][i] = list.get(i);
        }
        list.clear();
        mOrder(root);
        result[1] = new int[list.size()];
        for (int i = 0; i < list.size(); i++) {
            result[1][i] = list.get(i);
        }
        list.clear();
        eOrder(root);
        result[2] = new int[list.size()];
        for (int i = 0; i < list.size(); i++) {
            result[2][i] = list.get(i);
        }
        return result;

    }


    List<Integer> list = new ArrayList<>();


    public void prevOrder(TreeNode root) {
        if (root == null) {
            return;
        }
        list.add(root.val);
        prevOrder(root.left);
        prevOrder(root.right);
    }
    public void mOrder(TreeNode root) {
        if (root == null) {
            return;
        }
        mOrder(root.left);
        list.add(root.val);
        mOrder(root.right);
    }
    public void eOrder(TreeNode root) {
        if (root == null) {
            return;
        }
        eOrder(root.left);
        eOrder(root.right);
        list.add(root.val);
    }
}
